package com.shigen.shop.comon;

/**
 * @author shigenfu
 * @date 2022/7/25 10:16 下午
 */

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 统一返回体
 *
 * @param <T>
 * @author shigenfu
 */

@Data
@AllArgsConstructor
public class Result<T> {

  /**
   * 状态码
   */
  private Integer status;
  /**
   * 消息内容
   */
  private String msg;
  /**
   * 返回数据
   */
  private T data;

  public static <T> Result<T> success(T data, String msg) {
    return new Result(200, msg, data);
  }

  public static <T> Result<T> success(String msg) {
    return new Result(200, msg, null);
  }

  public static <T> Result<T> success(T data) {
    return new Result(200, null, data);
  }

  public static <T> Result<T> err(Integer status, String msg) {
    return new Result(status, msg, null);
  }

  public static <T> Result<T> err(String msg) {
    return new Result(500, msg, null);
  }

  public Result(Integer status, String msg) {
    this.status = status;
    this.msg = msg;
  }

  public Result(Integer status, T data) {
    this.status = status;
    this.data = data;
  }
}

